package HomeWOrk2;


import java.util.Comparator;
import java.util.TreeSet;

public class Treeset {
    public static void main(String[] args) {
        TreeSet<Studentt> treeset = new TreeSet<>(new Comparator<Studentt>() {
            @Override
            public int compare(Studentt o1, Studentt o2) {
                int sum1 = o1.getChinese()+o1.getEnglish()+o1.getMath();
                int sum2 = o2.getChinese()+o2.getEnglish()+o2.getMath();
                int result =sum1-sum2;
                if (result==0){
                 result = o1.getChinese()-o2.getChinese();
                }
                if (result==0){
                    result=o1.getMath()-o2.getMath();
                }
                if (result==0){
                    result=o1.getEnglish()-o2.getEnglish();
                }
                if (result==0){
                    result = o1.getName().compareTo(o2.getName());
                }
                return result;
            }
        });
        treeset.add(new Studentt("张三",100,100,100));
        treeset.add(new Studentt("五三三",100,100,100));
        treeset.add(new Studentt("德玛",100,99,100));
        treeset.add(new Studentt("如如",100,100,99));
        for (Studentt studentt : treeset) {
            System.out.println(studentt);
        }
    }
}
